class ParkSpiderErrorCode:
    Unknow = -1
    Success = 0
    TaskRunning = 1
    TaskNotRunning = 2
    InvavlidPlatform = 3
    NotFoundTask = 4
    DatabaseConnectError = 5
    ProxyFail = 6
    InvalidProxy = 7
    InvalidCarNumber = 8
    SpiderError = 9
    RequestsLimit = 10
    NotFoundCar = 11
    NotFoundSuAccount = 12
    SuAccountEmpty = 13
    YimaAccountEmpty = 14
    YmiotAccountEmpty = 15
    JieAccountEmpty = 16
    YunAccountEmpty = 17
    YdtAccountEmpty = 18
    AirunAccountEmpty = 19

    def message(code: int):
        if code == ParkSpiderErrorCode.Unknow:
            return "未知错误"
        if code == ParkSpiderErrorCode.Success:
            return "操作成功"
        if code == ParkSpiderErrorCode.InvavlidPlatform:
            return "无效的平台"
        if code == ParkSpiderErrorCode.TaskRunning:
            return "任务正在运行"
        if code == ParkSpiderErrorCode.TaskNotRunning:
            return "任务未运行"
        if code == ParkSpiderErrorCode.NotFoundTask:
            return "任务不存在"
        if code == ParkSpiderErrorCode.DatabaseConnectError:
            return "数据库连接异常"
        if code == ParkSpiderErrorCode.ProxyFail:
            return "代理获取失败"
        if code == ParkSpiderErrorCode.InvalidProxy:
            return "获取到的代理无法使用"
        if code == ParkSpiderErrorCode.InvalidCarNumber:
            return "车牌错误"
        if code == ParkSpiderErrorCode.SpiderError:
            return "爬虫异常"
        if code == ParkSpiderErrorCode.RequestsLimit:
            return "操作太快"
        if code == ParkSpiderErrorCode.NotFoundCar:
            return "没有找到车辆"
        if code == ParkSpiderErrorCode.NotFoundSuAccount:
            return "缺少速停车用户配置"
        if code == ParkSpiderErrorCode.SuAccountEmpty:
            return "速停车无可用账号"
        if code == ParkSpiderErrorCode.YimaAccountEmpty:
            return "一码无可用账号"
        if code == ParkSpiderErrorCode.YmiotAccountEmpty:
            return "云盟无可用账号"
        if code == ParkSpiderErrorCode.JieAccountEmpty:
            return "捷停车无可用账号"
        if code == ParkSpiderErrorCode.YunAccountEmpty:
            return "智慧停车云无可用账号"
        if code == ParkSpiderErrorCode.YdtAccountEmpty:
            return "一点停无可用账号"
        if code == ParkSpiderErrorCode.AirunAccountEmpty:
            return "艾润停车王无可用账号"


class ParkSpiderError(Exception):
    def __init__(self, code: ParkSpiderErrorCode, context=None) -> None:
        super().__init__(code)
        self.code = code
        self.context = context

    def json(self):
        return {
            "code": self.code,
            "message": ParkSpiderErrorCode.message(self.code),
            "context": str(self.context),
        }


class BannedAccountError(Exception):
    def __init__(self, context=None) -> None:
        super().__init__(context)
        self.context = context

    def __repr__(self) -> str:
        return f"违规的账号: {self.context}"


class TokenExpireError(Exception):
    def __init__(self, context=None) -> None:
        super().__init__(context)
        self.context = context

    def __repr__(self) -> str:
        return f"Token过期: {self.context}"


class ProxyTimeoutError(Exception):
    def __init__(self, context=None) -> None:
        super().__init__(context)
        self.context = context

    def __repr__(self) -> str:
        return f"获取代理超时: {self.context}"
